﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
using Data_Access_Layer;
using System.Collections;

namespace Raporty
{
    public partial class Raporty : Form
    {
        public Raporty()
        {
            InitializeComponent();
        }

        private void Raporty_Load(object sender, EventArgs e)
        {
            dateTimePicker1.Format = DateTimePickerFormat.Custom;
            dateTimePicker1.CustomFormat = "MMMM yyyy";
            dateTimePicker1.ShowUpDown = true;
            chartIncome.Hide();
            chartOutcome.Hide();
        }

        private void btnGenerate_Click(object sender, EventArgs e)
        {
            prepareIncomeChart();
            chartIncome.Show();

            prepareOutcomeChart();
            chartOutcome.Show();
        }

        private void prepareOutcomeChart()
        {
            // Set Doughnut chart type
            chartOutcome.Series["Default"].ChartType = SeriesChartType.Pie;

            // Set label
            chartOutcome.Series["Default"].Label = "#VALY zł\n#PERCENT";
            chartOutcome.Series["Default"].LegendText = "#AXISLABEL";

            // Set labels style
            chartOutcome.Series["Default"]["PieLabelStyle"] = "Outside";

            // Set Doughnut radius percentage
            chartOutcome.Series["Default"]["DoughnutRadius"] = "30";

            // Enable 3D
            chartOutcome.ChartAreas["Default"].Area3DStyle.Enable3D = true;

            // Set drawing style
            chartOutcome.Series["Default"]["PieDrawingStyle"] = "SoftEdge";
            
            IEnumerable outcomeBind = DbManager.Instance.CategoriesSumByMonth(dateTimePicker1.Value, false);

            chartOutcome.DataSource = null;
            chartOutcome.DataSource = outcomeBind;

            chartOutcome.Series["Default"].XValueMember = "Category";
            chartOutcome.Series["Default"].YValueMembers = "Value";
            chartOutcome.Titles[0].Text = "Wykres wydatków za miesiąc " + dateTimePicker1.Value.ToString("MMMM yyyy");

            chartOutcome.DataBind();
        }

        private void prepareIncomeChart()
        {
            // Set Doughnut chart type
            chartIncome.Series["Default"].ChartType = SeriesChartType.Pie;

            // Set label
            chartIncome.Series["Default"].Label = "#VALY zł\n#PERCENT";
            chartIncome.Series["Default"].LegendText = "#AXISLABEL";

            // Set labels style
            chartIncome.Series["Default"]["PieLabelStyle"] = "Outside";

            // Set Doughnut radius percentage
            chartIncome.Series["Default"]["DoughnutRadius"] = "30";

            // Enable 3D
            chartIncome.ChartAreas["Default"].Area3DStyle.Enable3D = true;

            // Set drawing style
            chartIncome.Series["Default"]["PieDrawingStyle"] = "SoftEdge";
            
            IEnumerable incomeBind = DbManager.Instance.CategoriesSumByMonth(dateTimePicker1.Value, true);

            chartIncome.DataSource = null;
            chartIncome.DataSource = incomeBind;

            chartIncome.Series["Default"].XValueMember = "Category";
            chartIncome.Series["Default"].YValueMembers = "Value";
            chartIncome.Titles[0].Text = "Wykres przychodów za miesiąc " + dateTimePicker1.Value.ToString("MMMM yyyy");
            chartIncome.DataBind();

        }
    }
}
